package kgame5.kgui.kcomp.slaverpane {
import flash.display.MovieClip;
import flash.events.EventDispatcher;
import flash.events.MouseEvent;

import gs.TweenLite;

import kgame5.kutil.T;

/**
 * @author kk
 * 底部托盘儿的一个个的元素
 * mc_icon,这个是为了防止TweenLite混乱而用的，mc是move用的，mc_icon是缩放用的
 * 有2真，一个是正常，一个是鼠标放上变大的
 */
class SlaverItem extends EventDispatcher{
	
	private var 
		mc:MovieClip,
			mc_icon:MovieClip;
	private var idx:int;
	private var master:SmartSlaverPane;
	public function SlaverItem(idx:int,mc:MovieClip,master:SmartSlaverPane){
		this.master=master;
		this.idx=idx;
		this.mc=mc;
		mc_icon=mc.mc_icon;
		mc.addEventListener(MouseEvent.CLICK, onClick);
		mc.addEventListener(MouseEvent.ROLL_OVER, onRollOver);
		mc.addEventListener(MouseEvent.ROLL_OUT, onRollOut);
		
		deSelected();
		
		mc.useHandCursor=true;
		mc.buttonMode=true;
	}
	public function getMC():MovieClip{
		return mc;
	}
	public function selected(){
		T.p("selected",idx);
		mc_icon.gotoAndStop(2);
		TweenLite.killTweensOf(mc);
		TweenLite.to(mc_icon,SmartSlaverPane.DUR,{scaleX:2,scaleY:2});
	}
	public function deSelected(){
		T.p("deSelected",idx);
		mc_icon.gotoAndStop(1);
		TweenLite.killTweensOf(mc);
		TweenLite.to(mc_icon,SmartSlaverPane.DUR,{scaleX:1,scaleY:1});
		
		
	}
	public function moveTo(aimX:int){
		TweenLite.to(mc,SmartSlaverPane.DUR,{x:aimX});
	}
	private function onClick(e:MouseEvent){
		master.onItemClick(idx);
	}
	private function onRollOver(e:MouseEvent){
		selected();
		master.onItemRollOver(idx);
	}
	private function onRollOut(e:MouseEvent){
		//T.p("onRollOut");
		deSelected();
		master.onItemRollOut(idx);
	}
	
}//end of class
}
